package com.zhenyi.tuangou.index;

import org.hashids.Hashids;

import com.cenjiawen.common.IndexController;
import com.jfinal.aop.Before;
import com.jfinal.kit.PropKit;
import com.utils.AuthUtils;
import com.zhenyi.common.model.TgProduct;
import com.zhenyi.common.model.TgUser;
import com.zhenyi.tuangou.interceptor.AuthInterceptor;
import com.zhenyi.tuangou.interceptor.WXInterceptor;

//@Before(AuthInterceptor.class)
@Before({ AuthInterceptor.class, WXInterceptor.class })
public class TGController extends IndexController {
	protected final int PAGE_SIZE = 50;
	protected final String APP_ID = PropKit.get("appId");
	protected final String APP_SECRET = PropKit.get("appSecret");
	protected final Hashids hashids = new Hashids("zhenyi", 8);
	/**
	 * 开团没有成功
	 */
	protected final int GROUP_BUY_NO_PAY = 0;

	/**
	 * 获取当前用户
	 * 
	 * @return
	 */
	protected TgUser getUser() {
		String uid = AuthUtils.getTokenUid(this);
		return TgUser.dao.findById(Long.parseLong(uid));
		// return TgUser.dao.findById(20180709);
	}

	/**
	 * 轮播图url
	 * 
	 * @param id
	 * @return
	 */
	protected String[] getImages(String str) {
		if (str == null) {
			return null;
		}
		String[] images = str.split(";");
		return images;
	}

	/**
	 * 商品详情
	 * 
	 * @param productId
	 * @return
	 */
	protected TgProduct getProduc(Long productId) {
		TgProduct product = TgProduct.dao.findById(productId);
		return product;
	}

}
